import module namespace functx = "http://www.functx.com" at "WEB-INF/xquery/functx-1.0.xq";
declare variable $doc as node() external;

let $disallowed := ( 'forumdisplay', 'faq' )
let $forums :=
    for $a in $doc//a[starts-with(@href, 'http://www.christianforums.com/f') 
                        and not(functx:contains-any-of(@href, $disallowed))]
    
    (: Isolate forum ID (fXXX) from the link :)
    let $href := $a/@href
    let $indices := functx:index-of-string($href, '/')
    let $index := $indices[count($indices) - 1] (: length - 1 is / where fid begins :)
    let $href := replace(substring($href, $index), '/', '')
    
    where not(empty($a/text()))
    return
    <forum id="{$href}">{$a/text()}</forum>
    
return
<forums>
    {$forums}
</forums>